<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qimageiohandler.cpp -->
  <title>QImageIOPlugin Class | Qt GUI 5.14.2</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.14</a></td><td ><a href="qtgui-index.html">Qt GUI</a></td><td ><a href="qtgui-module.html">C++ Classes</a></td><td >QImageIOPlugin</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtgui-index.html">Qt 5.14.2 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QImageIOPlugin Class</h1>
<!-- $$$QImageIOPlugin-brief -->
<p>The QImageIOPlugin class defines an interface for writing an image format plugin. <a href="#details">More...</a></p>
<!-- @@@QImageIOPlugin -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QImageIOPlugin&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += gui</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="../qtcore/qobject.html">QObject</a></td></tr></table></div><ul>
<li><a href="qimageioplugin-members.html">List of all members, including inherited members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are <a href="../qtdoc/threads-reentrancy.html">reentrant</a>.</p>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> flags </td><td class="memItemRight bottomAlign"><b><a href="qimageioplugin.html#Capability-enum">Capabilities</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qimageioplugin.html#Capability-enum">Capability</a></b> { CanRead, CanWrite, CanReadIncremental }</td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qimageioplugin.html#QImageIOPlugin">QImageIOPlugin</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qimageioplugin.html#dtor.QImageIOPlugin">~QImageIOPlugin</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QImageIOPlugin::Capabilities </td><td class="memItemRight bottomAlign"><b><a href="qimageioplugin.html#capabilities">capabilities</a></b>(QIODevice *<i>device</i>, const QByteArray &amp;<i>format</i>) const = 0</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QImageIOHandler *</td><td class="memItemRight bottomAlign"><b><a href="qimageioplugin.html#create">create</a></b>(QIODevice *<i>device</i>, const QByteArray &amp;<i>format</i> = QByteArray()) const = 0</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QImageIOPlugin-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>QImageIOPlugin is a factory for creating <a href="qimageiohandler.html">QImageIOHandler</a> objects, which are used internally by <a href="qimagereader.html">QImageReader</a> and <a href="qimagewriter.html">QImageWriter</a> to add support for different image formats to Qt.</p>
<p>Writing an image I/O plugin is achieved by subclassing this base class, reimplementing the pure virtual functions <a href="qimageioplugin.html#capabilities">capabilities</a>() and <a href="qimageioplugin.html#create">create</a>(), and exporting the class with the <a href="../qtcore/qtplugin.html#Q_PLUGIN_METADATA">Q_PLUGIN_METADATA</a>() macro. See <a href="../qtdoc/plugins-howto.html">How to Create Qt Plugins</a> for details.</p>
<p>An image format plugin can support three capabilities: reading (<a href="qimageioplugin.html#Capability-enum">CanRead</a>), writing (<a href="qimageioplugin.html#Capability-enum">CanWrite</a>) and <i>incremental</i> reading (<a href="qimageioplugin.html#Capability-enum">CanReadIncremental</a>). Reimplement <a href="qimageioplugin.html#capabilities">capabilities</a>() in you subclass to expose the capabilities of your image format.</p>
<p><a href="qimageioplugin.html#create">create</a>() should create an instance of your <a href="qimageiohandler.html">QImageIOHandler</a> subclass, with the provided device and format properly set, and return this handler.</p>
<p>The json metadata file for the plugin needs to contain information about the image formats the plugins supports, together with the corresponding MIME types (one for each format). For a jpeg plugin, this could, for example, look as follows:</p>
<pre class="cpp">

  {
    <span class="string">&quot;Keys&quot;</span>: <span class="operator">[</span> <span class="string">&quot;jpg&quot;</span><span class="operator">,</span> <span class="string">&quot;jpeg&quot;</span> <span class="operator">]</span><span class="operator">,</span>
    <span class="string">&quot;MimeTypes&quot;</span>: <span class="operator">[</span> <span class="string">&quot;image/jpeg&quot;</span><span class="operator">,</span> <span class="string">&quot;image/jpeg&quot;</span> <span class="operator">]</span>
  }

</pre>
<p>Different plugins can support different capabilities. For example, you may have one plugin that supports reading the GIF format, and another that supports writing. Qt will select the correct plugin for the job, depending on the return value of <a href="qimageioplugin.html#capabilities">capabilities</a>(). If several plugins support the same capability, Qt will select one arbitrarily.</p>
</div>
<p><b>See also </b><a href="qimageiohandler.html">QImageIOHandler</a> and <a href="../qtdoc/plugins-howto.html">How to Create Qt Plugins</a>.</p>
<!-- @@@QImageIOPlugin -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$Capability$$$CanRead$$$CanWrite$$$CanReadIncremental -->
<h3 class="flags" id="Capability-enum"><a name="Capability-enum"></a>enum QImageIOPlugin::<span class="name">Capability</span><br/>flags QImageIOPlugin::<span class="name">Capabilities</span></h3>
<p>This enum describes the capabilities of a <a href="qimageioplugin.html">QImageIOPlugin</a>.</p>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QImageIOPlugin::CanRead</code></td><td class="topAlign tblval"><code>0x1</code></td><td class="topAlign">The plugin can read images.</td></tr>
<tr><td class="topAlign"><code>QImageIOPlugin::CanWrite</code></td><td class="topAlign tblval"><code>0x2</code></td><td class="topAlign">The plugin can write images.</td></tr>
<tr><td class="topAlign"><code>QImageIOPlugin::CanReadIncremental</code></td><td class="topAlign tblval"><code>0x4</code></td><td class="topAlign">The plugin can read images incrementally.</td></tr>
</table></div>
<p>The Capabilities type is a typedef for <a href="../qtcore/qflags.html">QFlags</a>&lt;Capability&gt;. It stores an OR combination of Capability values.</p>
<!-- @@@Capability -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QImageIOPlugin[overload1]$$$QImageIOPluginQObject* -->
<h3 class="fn" id="QImageIOPlugin"><a name="QImageIOPlugin"></a>QImageIOPlugin::<span class="name">QImageIOPlugin</span>(<span class="type"><a href="../qtcore/qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<p>Constructs an image plugin with the given <i>parent</i>. This is invoked automatically by the moc generated code that exports the plugin.</p>
<!-- @@@QImageIOPlugin -->
<!-- $$$~QImageIOPlugin[overload1]$$$~QImageIOPlugin -->
<h3 class="fn" id="dtor.QImageIOPlugin"><a name="dtor.QImageIOPlugin"></a><code>[virtual] </code>QImageIOPlugin::<span class="name">~QImageIOPlugin</span>()</h3>
<p>Destroys the picture format plugin.</p>
<p>You never have to call this explicitly. Qt destroys a plugin automatically when it is no longer used.</p>
<!-- @@@~QImageIOPlugin -->
<!-- $$$capabilities[overload1]$$$capabilitiesQIODevice*constQByteArray& -->
<h3 class="fn" id="capabilities"><a name="capabilities"></a><code>[pure virtual] </code><span class="type"><a href="qimageioplugin.html#Capability-enum">QImageIOPlugin::Capabilities</a></span> QImageIOPlugin::<span class="name">capabilities</span>(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span> *<i>device</i>, const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>format</i>) const</h3>
<p>Returns the capabilities of the plugin, based on the data in <i>device</i> and the format <i>format</i>. If <i>device</i> is <code>0</code>, it should simply report whether the format can be read or written. Otherwise, it should attempt to determine whether the given format (or any format supported by the plugin if <i>format</i> is empty) can be read from or written to <i>device</i>. It should do this without changing the state of <i>device</i> (typically by using <a href="../qtcore/qiodevice.html#peek">QIODevice::peek</a>()).</p>
<p>For example, if the <a href="qimageioplugin.html">QImageIOPlugin</a> supports the BMP format, <i>format</i> is either empty or <code>&quot;bmp&quot;</code>, and the data in the device starts with the characters <code>&quot;BM&quot;</code>, this function should return <a href="qimageioplugin.html#Capability-enum">CanRead</a>. If <i>format</i> is <code>&quot;bmp&quot;</code>, <i>device</i> is <code>0</code> and the handler supports both reading and writing, this function should return <a href="qimageioplugin.html#Capability-enum">CanRead</a> | <a href="qimageioplugin.html#Capability-enum">CanWrite</a>.</p>
<p>Format names are always given in lower case.</p>
<!-- @@@capabilities -->
<!-- $$$create[overload1]$$$createQIODevice*constQByteArray& -->
<h3 class="fn" id="create"><a name="create"></a><code>[pure virtual] </code><span class="type"><a href="qimageiohandler.html">QImageIOHandler</a></span> *QImageIOPlugin::<span class="name">create</span>(<span class="type"><a href="../qtcore/qiodevice.html">QIODevice</a></span> *<i>device</i>, const <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> &amp;<i>format</i> = QByteArray()) const</h3>
<p>Creates and returns a <a href="qimageiohandler.html">QImageIOHandler</a> subclass, with <i>device</i> and <i>format</i> set. The <i>format</i> must come from the values listed in the <code>&quot;Keys&quot;</code> entry in the plugin metadata, or be empty. If it is empty, the data in <i>device</i> must have been recognized by the <a href="qimageioplugin.html#capabilities">capabilities</a>() method (with a likewise empty format).</p>
<p>Format names are always given in lower case.</p>
<!-- @@@create -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
